<?php
namespace App\Services;

use App\Models\Goods;

class GoodsService
{

	public function saveGoods($data, $id = null)
	{
		if(!$id)
		{
		    $goods = Goods::create($data);  	
		}
		else
		{
			$goods = Goods::find($id);
			$goods->update($data);
		}
		if(!empty($data['attr'])) {
			$goods->saveAttr($data['attr']);
		}
		if(!empty($data['picture']))
		{
			$goods->savePictures($data['picture']);
		}
		
		return $goods;
	}
}